package com.ag.answergames.controller;

import com.ag.answergames.entity.QuestionEntity;
import com.ag.answergames.service.question.QuestionService;
import com.ag.answergames.vo.QuestionCheckRequestVO;
import com.ag.answergames.vo.QuestionStoreVO;
import com.ag.answergames.vo.QuestionWrongVO;
import com.ag.answergames.vo.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/back/question")
public class QuestionController {


    @Autowired
    QuestionService questionService;


    /**
     * 一次查一条试题数据（随机查询后期修改）
     * @param questionStoreVO
     * @return
     */
    @PostMapping("/findOnlyOne")
    public Result<QuestionEntity> findOnlyOne(@RequestBody QuestionStoreVO questionStoreVO){

        Result<QuestionEntity> result = questionService.findOnlyOne(questionStoreVO);

        return result;
    }

    /**
     * 一次查一条错误集试题数据（随机查询后期修改）
     * @param questionWrongVO
     * @return
     */
    @PostMapping("/findOneWrong")
    public Result<QuestionEntity> findOneWrong(@RequestBody QuestionWrongVO questionWrongVO){

        Result<QuestionEntity> result = questionService.findOneWrong(questionWrongVO);

        return result;
    }

    /**
     * 查找所有班级
     * @param
     * @return
     */
    @PostMapping("/findAllGrade")
    public Result<List<String>> findAllGrade(){
        Result result = questionService.findAllGrade();
        return result;
    }

    /**
     * 查找所学科
     * @param
     * @return
     */
    @PostMapping("/findAllSubject")
    public Result<List<String>> findAllSubject(){
        Result result = questionService.findAllSubject();
        return result;
    }


    /**
     * 增加错题到错题集
     * @param questionCheckRequestVO
     * @return
     */
    @PostMapping("/add")
    public Result<Integer> add(@RequestBody QuestionCheckRequestVO questionCheckRequestVO){

        Result add = questionService.add(questionCheckRequestVO);

        return add;
    }

    /**
     * 错题集记录更新
     * @param questionCheckRequestVO
     * @return
     */
    @PostMapping("/wrongQuestionCount")
    public Result<Integer> wrongQuestionCount(@RequestBody QuestionCheckRequestVO questionCheckRequestVO){
        Result wrongQuestionCount = questionService.wrongQuestionCount(questionCheckRequestVO);
        return wrongQuestionCount;
    }


    /**
     * 逻辑删除试题库试题
     * @param userId,questionId,isDeleted
     * @return
     */
    @PostMapping("/questionIsDeleted")
    public Result<Integer> questionIsDeleted(@RequestParam long userId,@RequestParam long questionId, @RequestParam int isDeleted){
        Result update = questionService.questionIsDeleted(userId, questionId, isDeleted);
        return update;
    }



    /**
     * 检测选择的选项是否正确
     * @param
     * @return
     */
    @PostMapping("/checkChoose")
    public Result<List<String>> checkChoose(@RequestBody QuestionCheckRequestVO questionCheckRequestVO){
        Result checkResult = questionService.checkChoose(questionCheckRequestVO);
        return checkResult;
    }


}
